package trunk.control;


import trunk.res.R;
import trunk.utility.FileAccess;

import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by IntelliJ IDEA.
 * User: yipeipei
 * Date: 12/25/11
 * Time: 12:57 AM
 * To change this template use File | Settings | File Templates.
 */
public class DataPacket {
    /*Instruction Data*/
    protected static HashMap<String, ArrayList<String>> ACTION = new HashMap<String, ArrayList<String>>();
    protected static LinkedList<String> FT = new LinkedList<String>();
    protected static LinkedList<LinkedList<String>> ST = new LinkedList<LinkedList<String>>();
    protected static LinkedList<LinkedList<String>> DT = new LinkedList<LinkedList<String>>();
    protected static LinkedList<LinkedList<String>> ET = new LinkedList<LinkedList<String>>();
    
    //initialize ACTION
    static {
        FileAccess fileAccess = new FileAccess(R.file.ACTION);
        while (fileAccess.hasNextLine()) {
            String Key = fileAccess.readLine();
            ArrayList<String> Value = new ArrayList<String>();
            if (fileAccess.hasNextLine()) {
                String[] actions = fileAccess.readLine().split(":");
                for (String action : actions) {
                    Value.add(action);
                }
            }
            ACTION.put(Key, Value);
        }
    }
    
    //initialize FT, ST, DT, ET
    static {
        //FT
        {
            FT.add("M->IR");
            FT.add("PC+1->PC");
        }

        //ST
        {
            LinkedList<String> ST1 = new LinkedList<String>();
            ST1.add("R0->MAR");
            ST1.add("M->MDR->C");
            ST.add(ST1);

            LinkedList<String> ST2 = new LinkedList<String>();
            ST2.add("R0-1->R0,MAR");
            ST2.add("M->MDR->C");
            ST.add(ST2);

            LinkedList<String> ST3 = new LinkedList<String>();
            ST3.add("R0->MAR");
            ST3.add("M->MDR->C");
            ST3.add("R0+1->R0");
            ST.add(ST3);
            
            LinkedList<String> ST4 = new LinkedList<String>();
            ST4.add("R0->MAR");
            ST4.add("M->MDR->C");
            ST4.add("R0+1->R0");
            ST4.add("C->MAR");
            ST4.add("M->MDR->C");
            ST.add(ST4);
            
            LinkedList<String> ST5 = new LinkedList<String>();
            ST5.add("PC->MAR");
            ST5.add("M->MDR->C");
            ST5.add("PC+1->PC");
            ST5.add("C+R0->MAR");
            ST5.add("M->MDR->C");
            ST.add(ST5);
       }
        
        //DT
        {
            LinkedList<String> DT1 = new LinkedList<String>();
            DT1.add("R1->MAR");
            DT1.add("M->MDR->D");
            DT.add(DT1);

            LinkedList<String> DT2 = new LinkedList<String>();
            DT2.add("R1-1->R1,MAR");
            DT2.add("M->MDR->D");
            DT.add(DT2);

            LinkedList<String> DT3 = new LinkedList<String>();
            DT3.add("R1->MAR");
            DT3.add("M->MDR->D");
            DT3.add("R1+1->R1");
            DT.add(DT3);
            
            LinkedList<String> DT4 = new LinkedList<String>();
            DT4.add("R1->MAR");
            DT4.add("M->MDR->D");
            DT4.add("R1+1->R1");
            DT4.add("D->MAR");
            DT4.add("M->MDR->D");
            DT.add(DT4);
            
            LinkedList<String> DT5 = new LinkedList<String>();
            DT5.add("PC->MAR");
            DT5.add("M->MDR->D");
            DT5.add("PC+1->PC");
            DT5.add("D+R1->MAR");
            DT5.add("M->MDR->D");
            DT.add(DT5);
       }
        
       
    }

    
}
